<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <meta name="description" content="Python数据分析与可视化实践前言“得半日之闲，可抵十年尘梦”一卷书，一壶茶，御六气，游无穷。自古以来，我国便有喜爱读书的传统
研究对象书籍、作家和出版社" />
  

  
  
  
  
  
  
  <title>PythonDataAnalysis_report | 土木工程在读。。</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="Python数据分析与可视化实践前言“得半日之闲，可抵十年尘梦”一卷书，一壶茶，御六气，游无穷。自古以来，我国便有喜爱读书的传统 研究对象书籍、作家和出版社">
<meta property="og:type" content="article">
<meta property="og:title" content="PythonDataAnalysis_report">
<meta property="og:url" content="https://civilprogrammer.gitee.io/2020/05/11/PythonDataAnalysis-report/index.html">
<meta property="og:site_name" content="土木工程在读。。">
<meta property="og:description" content="Python数据分析与可视化实践前言“得半日之闲，可抵十年尘梦”一卷书，一壶茶，御六气，游无穷。自古以来，我国便有喜爱读书的传统 研究对象书籍、作家和出版社">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://civilprogrammer.gitee.io/2020/05/11/PythonDataAnalysis-report/Charts_backup/PriceRange_funnel.png">
<meta property="og:image" content="https://civilprogrammer.gitee.io/2020/05/11/PythonDataAnalysis-report/Charts_backup/Top10PubsInBookNums_radar.png">
<meta property="og:image" content="https://civilprogrammer.gitee.io/2020/05/11/PythonDataAnalysis-report/Charts_backup/TypicalPublishers_timeline_bar.png">
<meta property="og:image" content="https://civilprogrammer.gitee.io/2020/05/11/PythonDataAnalysis-report/Charts_backup/TypicalPublishers_timeline_pie.png">
<meta property="article:published_time" content="2020-05-10T16:02:05.000Z">
<meta property="article:modified_time" content="2020-11-18T12:37:01.406Z">
<meta property="article:author" content="CivilProgrammer">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://civilprogrammer.gitee.io/2020/05/11/PythonDataAnalysis-report/Charts_backup/PriceRange_funnel.png">
  
  
    <link rel="icon" href="/CivilProgrammer/css/images/favicon.ico">
  
  
<link rel="stylesheet" href="/CivilProgrammer/css/style.css">

  

  
  <!-- baidu webmaster push -->
  <script src='//push.zhanzhang.baidu.com/push.js'></script>
<meta name="generator" content="Hexo 5.0.0"></head>
<body class="home blog custom-background custom-font-enabled single-author">
  <div id="page" class="hfeed site">
      <header id="masthead" class="site-header" role="banner">
    <hgroup>
      <h1 class="site-title">
        <a href="/CivilProgrammer/" title="土木工程在读。。" rel="home">土木工程在读。。</a>
      </h1>
      
        <h2 class="site-description hitokoto"></h2>
        <script type="text/javascript" src="https://v1.hitokoto.cn/?encode=js"></script>
      
    </hgroup>

    <nav id="site-navigation" class="main-navigation" role="navigation">
            <button class="menu-toggle">菜单</button>
            <a class="assistive-text" href="/#content" title="跳至内容">跳至内容</a><!--TODO-->
            <div class="menu-main-container">
                <ul id="menu-main" class="nav-menu">
                
                    <li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="/CivilProgrammer/">Home</a></li>
                
                    <li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="/CivilProgrammer/archives">Archives</a></li>
                
                </ul>
            </div>
    </nav>
</header>

      <div id="main" class="wrapper">
        <div id="primary" class="site-content"><div id="content" role="main"><article id="post-PythonDataAnalysis-report" class="post-PythonDataAnalysis-report post type-post status-publish format-standard hentry">
    <!---->

      <header class="entry-header">
        
        
  
    <h1 class="entry-title article-title">
      PythonDataAnalysis_report
    </h1>
  

        
        <div class="comments-link">
            
            <a href="javascript:void(0);" data-url="https://civilprogrammer.gitee.io/2020/05/11/PythonDataAnalysis-report/" data-id="ckl9naiij000on8vlgsl60b27" class="leave-reply bdsharebuttonbox" data-cmd="more">Share</a>
        </div><!-- .comments-link -->
      </header><!-- .entry-header -->

    <div class="entry-content">
      
        <h1 id="Python数据分析与可视化实践"><a href="#Python数据分析与可视化实践" class="headerlink" title="Python数据分析与可视化实践"></a>Python数据分析与可视化实践</h1><h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>“得半日之闲，可抵十年尘梦”一卷书，一壶茶，御六气，游无穷。自古以来，我国便有喜爱读书的传统</p>
<h3 id="研究对象"><a href="#研究对象" class="headerlink" title="研究对象"></a>研究对象</h3><pre><code>书籍、作家和出版社</code></pre>
<a id="more"></a>
<h3 id="研究方式"><a href="#研究方式" class="headerlink" title="研究方式"></a>研究方式</h3><pre><code>原始数据是多个excel表格形式，首先将其合并为一个csv格式的文件，再生成DataFrame格式的数据，主要利用pandas中的groupby进行分组分析</code></pre>
<h3 id="研究意义"><a href="#研究意义" class="headerlink" title="研究意义"></a>研究意义</h3><pre><code>近年来，在全球信息化的浪潮下，图书种类纷繁复杂，各种书籍良莠不齐。因此，对现在市面上的图书进行数据分析，了解各个作家和出版社的水平，是多而杂，还是少而精，亦或是既保证数量又保证质量，是具有实际意义的</code></pre>
<h3 id="图表种类"><a href="#图表种类" class="headerlink" title="图表种类"></a>图表种类</h3><pre><code>- 漏斗图：各价格区间的书籍数量
- 柱状图和折线图：高产作家前20的作品数量和平均评分
- 雷达图：高产出版社前10的平均评分、出版数量、平均价格
- 柱状图（时间轴）：文学领域和科技领域具有代表性的出版社每年的出版数量和平均评分
- 饼图（时间轴）：具有代表性的出版社每年出版数量*更加直观*的展示  </code></pre>
<h3 id="数据来源"><a href="#数据来源" class="headerlink" title="数据来源"></a>数据来源</h3><pre><code>https://gitee.com/reference/doubanbook30000.git</code></pre>
<h2 id="程序分析与设计-有些注释太长，详见源代码"><a href="#程序分析与设计-有些注释太长，详见源代码" class="headerlink" title="程序分析与设计(有些注释太长，详见源代码)"></a>程序分析与设计(有些注释太长，详见源代码)</h2><h3 id="导入库"><a href="#导入库" class="headerlink" title="导入库"></a>导入库</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">from</span> tqdm <span class="keyword">import</span> tqdm</span><br><span class="line"><span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line"><span class="keyword">import</span> re</span><br><span class="line"><span class="keyword">import</span> math</span><br><span class="line"><span class="keyword">import</span> pyecharts.options <span class="keyword">as</span> opts</span><br><span class="line"><span class="keyword">from</span> pyecharts.charts <span class="keyword">import</span> Bar, Line, Radar, Pie, Timeline, Funnel</span><br></pre></td></tr></table></figure>
<blockquote>
<p>os：用于读取excel文件<br>tqdm：用于生成进度条效果，增加用户体验<br>pandas：数据处理<br>re：匹配数据中的关键信息并提取<br>math：用指数函数扩大数据间的差异<br>pyecharts：用于数据可视化</p>
</blockquote>
<h3 id="函数设计"><a href="#函数设计" class="headerlink" title="函数设计"></a>函数设计</h3><ul>
<li><p>合并多个excel文件，最后写入一个txt文件中</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">MergeFiles</span>() -&gt; list:</span></span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    合并多个excel文件，最后写入一个txt文件中\n</span></span><br><span class="line"><span class="string">    :return: 每个元素是csv格式文件每一行切分过后的列表的列表</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    dir = <span class="string">&quot;./RawData&quot;</span>  <span class="comment"># 设置工作路径</span></span><br><span class="line">    frames = []  <span class="comment"># 每个文件读成一个dataframe，存到frames列表中</span></span><br><span class="line">    <span class="keyword">for</span> root, dirs, files <span class="keyword">in</span> os.walk(dir):</span><br><span class="line">        <span class="keyword">for</span> file <span class="keyword">in</span> tqdm(files):</span><br><span class="line">            df = pd.read_excel(os.path.join(root, file))  <span class="comment"># excel转换成DataFrame</span></span><br><span class="line">            frames.append(df)</span><br><span class="line">    result = pd.concat(frames) <span class="comment"># 合并所有数据</span></span><br><span class="line">    <span class="comment"># 删除无用的列</span></span><br><span class="line">    <span class="keyword">del</span> result[<span class="string">&#x27;图片地址&#x27;</span>]</span><br><span class="line">    <span class="keyword">del</span> result[<span class="string">&#x27;URL入口&#x27;</span>]</span><br><span class="line">    <span class="comment"># 删除包含缺失值的行</span></span><br><span class="line">    result_cleaned = result.dropna()</span><br><span class="line">    result_cleaned = result_cleaned.drop_duplicates()</span><br><span class="line">    <span class="comment"># 用&#x27;&#123;&#x27;分隔，因为数据里本来就存在逗号，如 &quot;阿宅, 你已經死了!&quot;的形式(双引号里有逗号)</span></span><br><span class="line">    <span class="keyword">if</span> <span class="keyword">not</span> os.path.exists(<span class="string">&quot;./HandledData/merged.txt&quot;</span>):</span><br><span class="line">        result_cleaned.to_csv(<span class="string">&#x27;./HandledData/merged.txt&#x27;</span>, sep=<span class="string">&#x27;&#123;&#x27;</span>, index=<span class="literal">False</span>)</span><br><span class="line">    <span class="comment"># 读合并过后的txt文件，生成列表，每个元素是每一行切分过后的列表，</span></span><br><span class="line">    <span class="keyword">with</span> open(<span class="string">&quot;./HandledData/merged.txt&quot;</span>, encoding=<span class="string">&#x27;utf-8&#x27;</span>) <span class="keyword">as</span> file:</span><br><span class="line">        file.readline()  <span class="comment"># 让文件的指针指向第二行，把列名跳过，后续再定义</span></span><br><span class="line">        ls = [line.strip().split(<span class="string">&#x27;&#123;&#x27;</span>) <span class="keyword">for</span> line <span class="keyword">in</span> file]</span><br><span class="line">    print(<span class="string">&quot;Successfully ran MergeFiles&quot;</span>)</span><br><span class="line">    <span class="keyword">return</span> ls</span><br></pre></td></tr></table></figure>
</li>
<li><p>数据清洗  </p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">DataClean</span>(<span class="params">ls: list</span>) -&gt; list:</span></span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    清除无效数据：书名、出版信息、评价星数三者不全的;出版信息不全的;正则匹配不到年份的;正则匹配不到价格的\n</span></span><br><span class="line"><span class="string">    :param ls: 原列表，存放原始数据</span></span><br><span class="line"><span class="string">    :return: new_ls</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    new_ls = []</span><br><span class="line">    yearRegex = re.compile(<span class="string">r&#x27;(2|1)\d&#123;3&#125;&#x27;</span>)  <span class="comment"># 正则表达式匹配年份,待匹配字符串的格式有&quot;y-m-d&quot;、&quot;m-d-y&quot;,甚至还有July 16, 2005</span></span><br><span class="line">    priceRegex = re.compile(<span class="string">r&#x27;\d+(\.\d+)?&#x27;</span>)  <span class="comment"># 正则表达式匹配价格,待匹配格式：19.50元， USD 10.99等</span></span><br><span class="line">    <span class="keyword">for</span> idx <span class="keyword">in</span> tqdm(range(len(ls))):</span><br><span class="line">        <span class="keyword">if</span> len(ls[idx]) == <span class="number">3</span> <span class="keyword">and</span> len(ls[idx][<span class="number">1</span>].split(<span class="string">&#x27;/&#x27;</span>)) &gt;= <span class="number">4</span> <span class="keyword">and</span> \</span><br><span class="line">                yearRegex.search(ls[idx][<span class="number">1</span>].split(<span class="string">&#x27;/&#x27;</span>)[<span class="number">-2</span>].strip()) <span class="keyword">and</span> \</span><br><span class="line">                priceRegex.search(ls[idx][<span class="number">1</span>].split(<span class="string">&#x27;/&#x27;</span>)[<span class="number">-1</span>].strip()):</span><br><span class="line">            new_ls.append(ls[idx])</span><br><span class="line"></span><br><span class="line">    print(<span class="string">&quot;Successfully ran DataClean&quot;</span>)</span><br><span class="line">    <span class="keyword">return</span> new_ls</span><br></pre></td></tr></table></figure>
</li>
<li><p>生成DataFrame</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">GenerateListAndDf</span>(<span class="params">new_ls: list</span>) -&gt; pd.DataFrame:</span></span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    生成书名、作者、出版日期、价格、评价星数的列表，以生成DataFrame\n</span></span><br><span class="line"><span class="string">    :param new_ls: txt文件每一行切分后的列表</span></span><br><span class="line"><span class="string">    :return: 列名是&#x27;title&#x27;,&#x27;author&#x27;,&#x27;time&#x27;,&#x27;price&#x27;,&#x27;points&#x27;的DataFrame</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    yearRegex = re.compile(<span class="string">r&#x27;(2|1)\d&#123;3&#125;&#x27;</span>)  <span class="comment"># 正则表达式匹配年份,待匹配字符串的格式有&quot;y-m-d&quot;、&quot;m-d-y&quot;,甚至还有July 16, 2005</span></span><br><span class="line">    author = [x[<span class="number">1</span>].split(<span class="string">&#x27;/&#x27;</span>)[<span class="number">0</span>].strip() <span class="keyword">for</span> x <span class="keyword">in</span> tqdm(new_ls)]</span><br><span class="line">    price = [x[<span class="number">1</span>].split(<span class="string">&#x27;/&#x27;</span>)[<span class="number">-1</span>].strip() <span class="keyword">for</span> x <span class="keyword">in</span> tqdm(new_ls)]</span><br><span class="line">    time = [int(yearRegex.search(x[<span class="number">1</span>].split(<span class="string">&#x27;/&#x27;</span>)[<span class="number">-2</span>].strip()).group()) <span class="keyword">for</span> x <span class="keyword">in</span> tqdm(new_ls)]  <span class="comment"># 出版日期只取到年份</span></span><br><span class="line">    title = [x[<span class="number">0</span>].strip() <span class="keyword">for</span> x <span class="keyword">in</span> tqdm(new_ls)]</span><br><span class="line">    points = [float(x[<span class="number">2</span>]) <span class="keyword">for</span> x <span class="keyword">in</span> tqdm(new_ls)]</span><br><span class="line">    publisher = [x[<span class="number">1</span>].split(<span class="string">&#x27;/&#x27;</span>)[<span class="number">-3</span>].strip() <span class="keyword">for</span> x <span class="keyword">in</span> tqdm(new_ls)]</span><br><span class="line">    price = ConvertMoney(price)</span><br><span class="line">    names = [<span class="string">&#x27;title&#x27;</span>, <span class="string">&#x27;author&#x27;</span>, <span class="string">&#x27;publisher&#x27;</span>, <span class="string">&#x27;time&#x27;</span>, <span class="string">&#x27;price&#x27;</span>, <span class="string">&#x27;points&#x27;</span>]</span><br><span class="line">    dic = dict(zip(names, [title, author, publisher, time, price, points]))</span><br><span class="line">    Data = pd.DataFrame(dic)</span><br><span class="line">    Data = Data.dropna()</span><br><span class="line">    print(<span class="string">&quot;Successfully ran GenerateListAndDf&quot;</span>)</span><br><span class="line">    <span class="keyword">return</span> Data</span><br></pre></td></tr></table></figure>
</li>
<li><p>币值转换，原始数据中的价格是字符串形式，包含货币标记和数值</p>
<blockquote>
<p>首先利用正则表达式提取货币标记，集合去重后打印，人工筛选标记，如”￥”和’RMB’代表的是同一种货币</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">ConvertMoney</span>(<span class="params">price: list</span>) -&gt; list:</span></span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    将价格都换算成人民币为单位的\n</span></span><br><span class="line"><span class="string">    :param price: 每个元素是一个字符串的列表</span></span><br><span class="line"><span class="string">    :return: 每个元素是浮点数的列表</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    priceRegex = re.compile(<span class="string">r&#x27;\d+(,\d+)*\.?\d*&#x27;</span>)  <span class="comment"># 注意这里可能有三位分节法表示的数字</span></span><br><span class="line">    markRegex = re.compile((<span class="string">r&#x27;[^\d]+&#x27;</span>))  <span class="comment"># # 匹配价格中代表货币种类的部分</span></span><br><span class="line">    JapanList = [<span class="string">&#x27;税&#x27;</span>, <span class="string">&#x27;込&#x27;</span>, <span class="string">&#x27;円&#x27;</span>, <span class="string">&#x27;日&#x27;</span>, <span class="string">&#x27;JP&#x27;</span>, <span class="string">&#x27;NNT&#x27;</span>, <span class="string">&#x27;Yen&#x27;</span>]  <span class="comment"># 1日元=0.06632人民币</span></span><br><span class="line">    TaiWanList = [<span class="string">&#x27;N.T.&#x27;</span>, <span class="string">&#x27;NT&#x27;</span>, <span class="string">&#x27;NTD&#x27;</span>, <span class="string">&#x27;TWD&#x27;</span>, <span class="string">&#x27;台&#x27;</span>, <span class="string">&#x27;臺&#x27;</span>, <span class="string">&#x27;N.T&#x27;</span>, <span class="string">&#x27;nt&#x27;</span>]  <span class="comment"># 1新台币=0.2370人民币</span></span><br><span class="line">    SouthKoreaList = [<span class="string">&#x27;韩&#x27;</span>, <span class="string">&#x27;KRW&#x27;</span>]  <span class="comment"># 1韩元=0.005799人民币</span></span><br><span class="line">    HKList = [<span class="string">&#x27;HK&#x27;</span>, <span class="string">&#x27;港&#x27;</span>, <span class="string">&#x27;hk&#x27;</span>, <span class="string">&#x27;H.K.&#x27;</span>]  <span class="comment"># 1港元=0.9125人民币</span></span><br><span class="line">    UKList = [<span class="string">&#x27;£&#x27;</span>, <span class="string">&#x27;UK&#x27;</span>, <span class="string">&#x27;uk&#x27;</span>, <span class="string">&#x27;GBP&#x27;</span>]  <span class="comment"># 1英镑=8.7757人民币</span></span><br><span class="line">    EuropeList = [<span class="string">&#x27;EUROS&#x27;</span>, <span class="string">&#x27;€&#x27;</span>, <span class="string">&#x27;EUR&#x27;</span>]  <span class="comment"># 1欧元=7.6673人民币</span></span><br><span class="line">    SingaporeList = [<span class="string">&#x27;新元&#x27;</span>]  <span class="comment"># 1新加坡元=5.0076人民币</span></span><br><span class="line">    ThailandList = [<span class="string">&#x27;THB&#x27;</span>, <span class="string">&#x27;baht&#x27;</span>]  <span class="comment"># 1泰铢=0.2196人民币</span></span><br><span class="line">    MalaysiaList = [<span class="string">&#x27;RM&#x27;</span>]  <span class="comment"># 1马来西亚林吉特=1.6335人民币</span></span><br><span class="line">    CanadaList = [<span class="string">&#x27;CAD&#x27;</span>, <span class="string">&#x27;CAN&#x27;</span>, <span class="string">&#x27;CDN&#x27;</span>]  <span class="comment"># 1加元=5.0771人民币</span></span><br><span class="line">    USList = [<span class="string">&#x27;us&#x27;</span>, <span class="string">&#x27;US&#x27;</span>, <span class="string">&#x27;美&#x27;</span>, <span class="string">&#x27;$&#x27;</span>]  <span class="comment"># 1美元=7.0732人民币</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> tqdm(range(len(price))):</span><br><span class="line">        match_mark = markRegex.search(price[i])  <span class="comment"># 匹配价格中代表货币种类的部分</span></span><br><span class="line">        match_value = priceRegex.search(price[i])  <span class="comment"># 匹配价格的数值部分</span></span><br><span class="line">        <span class="keyword">if</span> match_mark <span class="keyword">and</span> match_value:  <span class="comment"># 事实上，match_value是恒为True的,它价格总不能没有阿拉伯数字而用文字表达吧</span></span><br><span class="line">            mark = match_mark.group()</span><br><span class="line">            value = float(match_value.group().replace(<span class="string">&#x27;,&#x27;</span>, <span class="string">&#x27;&#x27;</span>))  <span class="comment"># 将匹配到的数值字符串中的&#x27;,&#x27;删除,再转为浮点型</span></span><br><span class="line">            <span class="keyword">if</span> any(x <span class="keyword">in</span> mark <span class="keyword">for</span> x <span class="keyword">in</span> JapanList):</span><br><span class="line">                value *= <span class="number">0.06632</span></span><br><span class="line">            <span class="keyword">elif</span> any(x <span class="keyword">in</span> mark <span class="keyword">for</span> x <span class="keyword">in</span> TaiWanList):</span><br><span class="line">                value *= <span class="number">0.2370</span></span><br><span class="line">            <span class="keyword">elif</span> any(x <span class="keyword">in</span> mark <span class="keyword">for</span> x <span class="keyword">in</span> SouthKoreaList):</span><br><span class="line">                value *= <span class="number">0.005799</span></span><br><span class="line">            <span class="keyword">elif</span> any(x <span class="keyword">in</span> mark <span class="keyword">for</span> x <span class="keyword">in</span> HKList):</span><br><span class="line">                value *= <span class="number">0.9125</span></span><br><span class="line">            <span class="keyword">elif</span> any(x <span class="keyword">in</span> mark <span class="keyword">for</span> x <span class="keyword">in</span> UKList):</span><br><span class="line">                value *= <span class="number">8.7757</span></span><br><span class="line">            <span class="keyword">elif</span> any(x <span class="keyword">in</span> mark <span class="keyword">for</span> x <span class="keyword">in</span> EuropeList):</span><br><span class="line">                value *= <span class="number">7.6673</span></span><br><span class="line">            <span class="keyword">elif</span> any(x <span class="keyword">in</span> mark <span class="keyword">for</span> x <span class="keyword">in</span> SingaporeList):</span><br><span class="line">                value *= <span class="number">5.0076</span></span><br><span class="line">            <span class="keyword">elif</span> any(x <span class="keyword">in</span> mark <span class="keyword">for</span> x <span class="keyword">in</span> ThailandList):</span><br><span class="line">                value *= <span class="number">0.2196</span></span><br><span class="line">            <span class="keyword">elif</span> any (x <span class="keyword">in</span> mark <span class="keyword">for</span> x <span class="keyword">in</span> MalaysiaList):</span><br><span class="line">                value *= <span class="number">1.6335</span></span><br><span class="line">            <span class="keyword">elif</span> any(x <span class="keyword">in</span> mark <span class="keyword">for</span> x <span class="keyword">in</span> CanadaList):</span><br><span class="line">                value *= <span class="number">5.0771</span></span><br><span class="line">            <span class="keyword">elif</span> any(x <span class="keyword">in</span> mark <span class="keyword">for</span> x <span class="keyword">in</span> USList):  <span class="comment"># 倒数第二个换算美元，因为&quot;$&quot;在上述的币种中也存在,&quot;$&quot;单独存在时表示美元</span></span><br><span class="line">                value *= <span class="number">7.0732</span></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                value = value</span><br><span class="line">        <span class="keyword">elif</span> match_value:</span><br><span class="line">            value = value</span><br><span class="line">        price[i] = value</span><br><span class="line">    print(<span class="string">&quot;Successfully ran ConvertMoney&quot;</span>)</span><br><span class="line">    <span class="keyword">return</span> price</span><br></pre></td></tr></table></figure>
</li>
<li><p>生成高产作家前20的相关信息</p>
<blockquote>
<p>作家名称、作品数量、作品均分的列表</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">RankOfCompositionNums</span>(<span class="params">Data: pd.DataFrame</span>) -&gt; tuple:</span></span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    作品数量top20的作家\n</span></span><br><span class="line"><span class="string">    :param Data: DataFrame</span></span><br><span class="line"><span class="string">    :return: top20作家名称、作品数量、作品均分三个列表组成的元组</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    <span class="comment"># 作品数量前20的作家名称，因为简体繁体等原因，有重复，所以取前30，后续删除重复</span></span><br><span class="line">    Top20WritersNames = Data.groupby(<span class="string">&#x27;author&#x27;</span>).title.count().sort_values(ascending=<span class="literal">False</span>).index.to_list()[:<span class="number">30</span>]</span><br><span class="line">    <span class="keyword">del</span> Top20WritersNames[<span class="number">27</span>:<span class="number">29</span>]</span><br><span class="line">    <span class="keyword">del</span> Top20WritersNames[<span class="number">23</span>:<span class="number">25</span>]</span><br><span class="line">    <span class="keyword">del</span> Top20WritersNames[<span class="number">16</span>:<span class="number">22</span>]</span><br><span class="line">    <span class="comment"># 作品数量top20的作家的作品数量</span></span><br><span class="line">    Top20WritersNums = Data.groupby(<span class="string">&#x27;author&#x27;</span>).title.count().sort_values(ascending=<span class="literal">False</span>).to_list()[:<span class="number">30</span>]</span><br><span class="line">    <span class="keyword">del</span> Top20WritersNums[<span class="number">27</span>:<span class="number">29</span>]</span><br><span class="line">    <span class="keyword">del</span> Top20WritersNums[<span class="number">23</span>:<span class="number">25</span>]</span><br><span class="line">    <span class="keyword">del</span> Top20WritersNums[<span class="number">16</span>:<span class="number">22</span>]</span><br><span class="line">    AvgPoints = Data.groupby(<span class="string">&#x27;author&#x27;</span>).points.mean().to_dict()</span><br><span class="line">    Top20WritersPoints = [AvgPoints[x] <span class="keyword">for</span> x <span class="keyword">in</span> tqdm(Top20WritersNames)]</span><br><span class="line">    print(<span class="string">&quot;Successfully ran RankOfCompositionNums&quot;</span>)</span><br><span class="line">    <span class="keyword">return</span> Top20WritersNames, Top20WritersNums, Top20WritersPoints</span><br></pre></td></tr></table></figure>
</li>
<li><p>生成代表性出版社的相关信息</p>
<blockquote>
<p>各年份各出版社的评分、出版量及当年总出版量</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">DictOfDicts</span>(<span class="params">Data: pd.DataFrame</span>) -&gt; tuple:</span></span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;注释太多，详见源代码&#x27;&#x27;&#x27;</span></span><br><span class="line">    dic_1 = &#123;&#125;</span><br><span class="line">    publishers = [<span class="string">&#x27;机械工业出版社&#x27;</span>, <span class="string">&#x27;人民邮电出版社&#x27;</span>, <span class="string">&#x27;电子工业出版社&#x27;</span>, <span class="string">&#x27;清华大学出版社&#x27;</span>, <span class="string">&#x27;人民文学出版社&#x27;</span>, <span class="string">&#x27;上海译文出版社&#x27;</span>,<span class="string">&#x27;生活·读书·新知三联书店&#x27;</span>, <span class="string">&#x27;广西师范大学出版社&#x27;</span>]</span><br><span class="line">    grouped_1 = Data.groupby(<span class="string">&#x27;time&#x27;</span>)</span><br><span class="line">    grouped_2 = Data.groupby([<span class="string">&#x27;time&#x27;</span>, <span class="string">&#x27;publisher&#x27;</span>])  <span class="comment"># 根据两个列——出版年份和出版社——分组</span></span><br><span class="line">    value = grouped_1.title.count().to_list()  <span class="comment"># 各个年份总出版量的列表，只有数据，按照年份从早到晚的顺序</span></span><br><span class="line">    key = grouped_1.title.count().index.to_list()  <span class="comment"># 各个年份的列表</span></span><br><span class="line">    dic_2 = dict(zip(key, value))  <span class="comment"># 生成年份和出版数量对应的字典</span></span><br><span class="line">    <span class="comment"># dic_1是字典的嵌套,第一层:  年份:字典</span></span><br><span class="line">    <span class="comment">#                第二层:   出版社:列表(列表内包含该年该出版社出版的作品数量和平均分)</span></span><br><span class="line">    <span class="keyword">for</span> (year, pub), group <span class="keyword">in</span> tqdm(grouped_2):  <span class="comment"># 遍历根据多个列分组的GroupBy对象,(year, pub)是分组的列名的元组,group是这个组里的dataframe</span></span><br><span class="line">        <span class="keyword">if</span> year <span class="keyword">not</span> <span class="keyword">in</span> dic_1:</span><br><span class="line">            dic_1[year] = &#123;&#125;</span><br><span class="line">        AvgPoints = group.points.mean()</span><br><span class="line">        BookNum = group.title.count()</span><br><span class="line">        dic_1[year][pub] = [AvgPoints, BookNum]</span><br><span class="line">    data_points = &#123;&#125;</span><br><span class="line">    data_nums = &#123;&#125;</span><br><span class="line">    data_all_published = &#123;&#125;</span><br><span class="line">    <span class="keyword">for</span> year <span class="keyword">in</span> tqdm(range(<span class="number">2002</span>, <span class="number">2015</span>)):</span><br><span class="line">        data_points[year] = [dic_1[year][name][<span class="number">0</span>] <span class="keyword">for</span> name <span class="keyword">in</span> publishers]</span><br><span class="line">        data_nums[year] = [dic_1[year][name][<span class="number">1</span>] <span class="keyword">for</span> name <span class="keyword">in</span> publishers]</span><br><span class="line">        data_all_published[year] = dic_2[year]</span><br><span class="line">    <span class="comment"># &lt;class &#x27;numpy.int32&#x27;&gt;  data_nums的每一个值是一个列表，列表里的元素是numpy的数据类型，转成python的int类型</span></span><br><span class="line">    <span class="keyword">for</span> k <span class="keyword">in</span> tqdm(data_nums.keys()):</span><br><span class="line">        data_nums[k] = [int(x) <span class="keyword">for</span> x <span class="keyword">in</span> data_nums[k]]</span><br><span class="line">    print(<span class="string">&quot;Successfully ran DictOfDicts&quot;</span>)</span><br><span class="line">    <span class="keyword">return</span> data_points, data_nums, data_all_published</span><br></pre></td></tr></table></figure>
</li>
<li><p>生成高产出版社前10的相关信息</p>
<blockquote>
<p>出版物数量前10的出版社的评分、数量和价格排名</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">RankOfPublisher</span>(<span class="params">Data: pd.DataFrame</span>) -&gt; tuple:</span></span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    出版物数量前10的出版社的评分、数量和价格排名\n</span></span><br><span class="line"><span class="string">    :param Data: DataFrame</span></span><br><span class="line"><span class="string">    :return: tuple of five lists</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    NamesOfPubs = Data.groupby(<span class="string">&#x27;publisher&#x27;</span>).title.count().sort_values(ascending=<span class="literal">False</span>).index.to_list()[:<span class="number">10</span>]</span><br><span class="line">    BookNumsOfPubs = Data.groupby(<span class="string">&#x27;publisher&#x27;</span>).title.count().sort_values(ascending=<span class="literal">False</span>).to_list()[:<span class="number">10</span>]</span><br><span class="line">    AvgPointsOfAll = Data.groupby(<span class="string">&#x27;publisher&#x27;</span>).points.mean().to_dict()</span><br><span class="line">    PriceOfAllPubs = Data.groupby(<span class="string">&#x27;publisher&#x27;</span>).price.mean()</span><br><span class="line">    AvgPoints = [AvgPointsOfAll[x] <span class="keyword">for</span> x <span class="keyword">in</span> NamesOfPubs]</span><br><span class="line">    AvgPrice = [float(PriceOfAllPubs[x]) <span class="keyword">for</span> x <span class="keyword">in</span> NamesOfPubs]</span><br><span class="line">    PriceOfAllBooks = [float(x) <span class="keyword">for</span> x <span class="keyword">in</span> tqdm(Data.price.to_list())]  <span class="comment"># 浮点数列表，包含每一本书的价格</span></span><br><span class="line">    print(<span class="string">&quot;Successfully ran RankOfPublishers&quot;</span>)</span><br><span class="line">    <span class="keyword">return</span> BookNumsOfPubs, NamesOfPubs, AvgPoints, AvgPrice, PriceOfAllBooks</span><br></pre></td></tr></table></figure>
</li>
<li><p>绘制图表</p>
<blockquote>
<p>绘制信息见前言部分</p>
</blockquote>
<p>  柱状图和折线图</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">BarAndLine</span>(<span class="params">Top20WritersNames: list, Top20WritersNums: list, Top20WritersPoints: list</span>):</span></span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    高产作家(productive author)创作数量及其评分\n</span></span><br><span class="line"><span class="string">    :param Top20WritersNames: 高产作者前20名称的列表</span></span><br><span class="line"><span class="string">    :param Top20WritersNums: 高产作者前20各自的作品数量的列表</span></span><br><span class="line"><span class="string">    :param Top20WritersPoints: 高产作者前20的作品评分的列表</span></span><br><span class="line"><span class="string">    :return: 没有</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    <span class="keyword">global</span> dir_to_save</span><br><span class="line">    x_data = Top20WritersNames</span><br><span class="line">    bar = (</span><br><span class="line">        Bar(init_opts=opts.InitOpts(width=<span class="string">&quot;1000px&quot;</span>, height=<span class="string">&quot;500px&quot;</span>))  <span class="comment"># 指定图片大小</span></span><br><span class="line">            .add_xaxis(xaxis_data=x_data)</span><br><span class="line">            .add_yaxis(series_name=<span class="string">&quot;作品数量&quot;</span>, yaxis_data=Top20WritersNums, )</span><br><span class="line">            .extend_axis(</span><br><span class="line">            yaxis=opts.AxisOpts(</span><br><span class="line">                name=<span class="string">&quot;平均分&quot;</span>,</span><br><span class="line">                type_=<span class="string">&quot;value&quot;</span>,  <span class="comment"># 数值轴。还有“time”、“category”等选项，试了试发现画出来的图很奇怪，不深究了</span></span><br><span class="line">                min_=<span class="number">0</span>,</span><br><span class="line">                max_=<span class="number">10</span>,</span><br><span class="line">                interval=<span class="number">0.5</span>,</span><br><span class="line">                <span class="comment"># axislabel_opts=opts.LabelOpts(formatter=&quot;&#123;value&#125;&quot;), y轴刻度需要单位时设置，此时为评价分数，不用单位</span></span><br><span class="line">            )</span><br><span class="line">        )</span><br><span class="line">            .set_global_opts(</span><br><span class="line">            tooltip_opts=opts.TooltipOpts(</span><br><span class="line">                is_show=<span class="literal">True</span>, trigger=<span class="string">&quot;axis&quot;</span>, axis_pointer_type=<span class="string">&quot;cross&quot;</span></span><br><span class="line">            ),</span><br><span class="line">            xaxis_opts=opts.AxisOpts(</span><br><span class="line">                type_=<span class="string">&quot;category&quot;</span>,</span><br><span class="line">                axispointer_opts=opts.AxisPointerOpts(is_show=<span class="literal">True</span>, type_=<span class="string">&quot;shadow&quot;</span>),</span><br><span class="line">                axislabel_opts=opts.LabelOpts(rotate=<span class="number">-30</span>, font_size=<span class="number">18</span>)  <span class="comment"># x轴标签旋转，设置字体大小</span></span><br><span class="line">            ),</span><br><span class="line">            yaxis_opts=opts.AxisOpts(</span><br><span class="line">                name=<span class="string">&quot;作品数量&quot;</span>,</span><br><span class="line">                type_=<span class="string">&quot;value&quot;</span>,</span><br><span class="line">                min_=<span class="number">0</span>,</span><br><span class="line">                max_=<span class="number">300</span>,</span><br><span class="line">                interval=<span class="number">50</span>,</span><br><span class="line">                axislabel_opts=opts.LabelOpts(formatter=<span class="string">&quot;&#123;value&#125;&quot;</span>),</span><br><span class="line">                axistick_opts=opts.AxisTickOpts(is_show=<span class="literal">True</span>),</span><br><span class="line">                splitline_opts=opts.SplitLineOpts(is_show=<span class="literal">True</span>),</span><br><span class="line">            ),</span><br><span class="line">            title_opts=opts.TitleOpts(title=<span class="string">&#x27;高产作家创作数量及其评分&#x27;</span></span><br><span class="line">                                      , pos_left=<span class="string">&#x27;8%&#x27;</span>  <span class="comment"># 标题的位置 距离左边20%距离。</span></span><br><span class="line">                                      , title_textstyle_opts=opts.TextStyleOpts(color=<span class="string">&#x27;black&#x27;</span></span><br><span class="line">                                                                                , font_size=<span class="number">20</span></span><br><span class="line">                                                                                , font_weight=<span class="string">&#x27;bold&#x27;</span></span><br><span class="line">                                                                                )  <span class="comment"># 大标题文字的格式配置</span></span><br><span class="line">                                      )</span><br><span class="line">        )</span><br><span class="line">    )</span><br><span class="line">    line = (</span><br><span class="line">        Line()</span><br><span class="line">            .add_xaxis(xaxis_data=x_data)</span><br><span class="line">            .add_yaxis(</span><br><span class="line">            series_name=<span class="string">&quot;平均评分&quot;</span>,</span><br><span class="line">            yaxis_index=<span class="number">1</span>,</span><br><span class="line">            y_axis=Top20WritersPoints,</span><br><span class="line">            label_opts=opts.LabelOpts(is_show=<span class="literal">False</span>),</span><br><span class="line">        )</span><br><span class="line">    )</span><br><span class="line">    bar.overlap(line).render(dir_to_save + <span class="string">&quot;ProductiveAuthor_bar_and_line.html&quot;</span>)</span><br><span class="line">    print(<span class="string">&quot;Successfully drew ProductiveAuthor_bar_and_line&quot;</span>)</span><br></pre></td></tr></table></figure>
<p>  时间线饼图  </p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">TimelinePie</span>(<span class="params">data_nums: dict</span>):</span></span><br><span class="line">    <span class="keyword">global</span> dir_to_save</span><br><span class="line">    attr = [<span class="string">&#x27;机械工业出版社&#x27;</span>, <span class="string">&#x27;人民邮电出版社&#x27;</span>, <span class="string">&#x27;电子工业出版社&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;清华大学出版社&#x27;</span>, <span class="string">&#x27;人民文学出版社&#x27;</span>, <span class="string">&#x27;上海译文出版社&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;生活·读书·新知三联书店&#x27;</span>, <span class="string">&#x27;广西师范大学出版社&#x27;</span>]</span><br><span class="line">    tl = Timeline()</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> tqdm(range(<span class="number">2002</span>, <span class="number">2015</span>)):</span><br><span class="line">        pie = (</span><br><span class="line">            Pie()</span><br><span class="line">                .add(</span><br><span class="line">                <span class="string">&quot;&quot;</span>,</span><br><span class="line">                [list(z) <span class="keyword">for</span> z <span class="keyword">in</span> zip(attr, data_nums[i])],</span><br><span class="line">                rosetype=<span class="string">&quot;radius&quot;</span>,</span><br><span class="line">                radius=[<span class="string">&quot;30%&quot;</span>, <span class="string">&quot;55%&quot;</span>],</span><br><span class="line">            )</span><br><span class="line">                .set_global_opts(title_opts=opts.TitleOpts(<span class="string">&quot;8个出版社的&#123;&#125;年出版量对比&quot;</span>.format(i),</span><br><span class="line">                                                           pos_top=<span class="string">&#x27;15%&#x27;</span>)</span><br><span class="line">                                 )</span><br><span class="line">        )</span><br><span class="line">        tl.add(pie, <span class="string">&quot;&#123;&#125;年&quot;</span>.format(i))</span><br><span class="line">    tl.add_schema(is_auto_play=<span class="literal">True</span>, play_interval=<span class="number">1000</span>)</span><br><span class="line">    tl.render(dir_to_save + <span class="string">&quot;TypicalPublishers_timeline_pie.html&quot;</span>)</span><br><span class="line">    print(<span class="string">&quot;Successfully drew TypicalPublishers_timeline_pie&quot;</span>)</span><br></pre></td></tr></table></figure>
<p>  时间线柱状图</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">TimelineBar</span>(<span class="params">Data: pd.DataFrame</span>):</span></span><br><span class="line">    <span class="keyword">global</span> dir_to_save</span><br><span class="line">    data_points, data_nums = DictOfDicts(Data)[:<span class="number">2</span>]</span><br><span class="line">    total_data = &#123;&#125;</span><br><span class="line">    name_list = [<span class="string">&#x27;机械工业出版社&#x27;</span>, <span class="string">&#x27;人民邮电出版社&#x27;</span>, <span class="string">&#x27;电子工业出版社&#x27;</span>,</span><br><span class="line">                 <span class="string">&#x27;清华大学出版社&#x27;</span>, <span class="string">&#x27;人民文学出版社&#x27;</span>, <span class="string">&#x27;上海译文出版社&#x27;</span>,</span><br><span class="line">                 <span class="string">&#x27;生活·读书·新知三联书店&#x27;</span>, <span class="string">&#x27;广西师范大学出版社&#x27;</span>]</span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">format_data</span>(<span class="params">data: dict</span>) -&gt; dict:</span></span><br><span class="line">        <span class="keyword">for</span> year <span class="keyword">in</span> tqdm(range(<span class="number">2002</span>, <span class="number">2015</span>)):</span><br><span class="line">            max_data, sum_data = <span class="number">0</span>, <span class="number">0</span></span><br><span class="line">            temp = data[year]</span><br><span class="line">            max_data = max(temp)</span><br><span class="line">            <span class="keyword">for</span> i <span class="keyword">in</span> range(len(temp)):</span><br><span class="line">                sum_data += temp[i]</span><br><span class="line">                data[year][i] = &#123;<span class="string">&quot;name&quot;</span>: name_list[i], <span class="string">&quot;value&quot;</span>: temp[i]&#125;</span><br><span class="line">            data[str(year) + <span class="string">&quot;max&quot;</span>] = int(max_data / <span class="number">100</span>) * <span class="number">100</span></span><br><span class="line">            data[str(year) + <span class="string">&quot;sum&quot;</span>] = sum_data</span><br><span class="line">        <span class="keyword">return</span> data</span><br><span class="line">    total_data[<span class="string">&quot;dataPoints&quot;</span>] = format_data(data=data_points)</span><br><span class="line">    total_data[<span class="string">&quot;dataNums&quot;</span>] = format_data(data=data_nums)</span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get_year_overlap_chart</span>(<span class="params">year: int</span>) -&gt; Bar:</span></span><br><span class="line">        bar = (</span><br><span class="line">            Bar()</span><br><span class="line">                .add_xaxis(xaxis_data=name_list)</span><br><span class="line">                .add_yaxis(</span><br><span class="line">                series_name=<span class="string">&quot;NUMS&quot;</span>,</span><br><span class="line">                yaxis_data=total_data[<span class="string">&quot;dataNums&quot;</span>][year],</span><br><span class="line">                is_selected=<span class="literal">True</span>,</span><br><span class="line">                label_opts=opts.LabelOpts(is_show=<span class="literal">False</span>),</span><br><span class="line">            )</span><br><span class="line">                .add_yaxis(</span><br><span class="line">                series_name=<span class="string">&quot;POINTS&quot;</span>,</span><br><span class="line">                yaxis_data=total_data[<span class="string">&quot;dataPoints&quot;</span>][year],</span><br><span class="line">                is_selected=<span class="literal">True</span>,</span><br><span class="line">                yaxis_index=<span class="number">1</span>,  <span class="comment"># NUMS和POINTS两个yaxis数量级不同，故分别控制不同的坐标轴</span></span><br><span class="line">                label_opts=opts.LabelOpts(is_show=<span class="literal">False</span>),</span><br><span class="line">            )</span><br><span class="line">                .extend_axis(</span><br><span class="line">                yaxis=opts.AxisOpts(</span><br><span class="line">                    name=<span class="string">&quot;平均评分&quot;</span>,</span><br><span class="line">                    type_=<span class="string">&quot;value&quot;</span>,  <span class="comment"># 数值轴。还有“time”、“category”等选项，试了试发现画出来的图很奇怪，不深究了</span></span><br><span class="line">                    min_=<span class="number">7.5</span>,</span><br><span class="line">                    max_=<span class="number">9</span>,</span><br><span class="line">                    interval=<span class="number">0.2</span>,</span><br><span class="line">                )</span><br><span class="line">            )</span><br><span class="line">                .set_global_opts(</span><br><span class="line">                title_opts=opts.TitleOpts(</span><br><span class="line">                    title=<span class="string">&quot;&#123;&#125;代表性出版社出版数量及评分情况&quot;</span>.format(year)),</span><br><span class="line">                tooltip_opts=opts.TooltipOpts(</span><br><span class="line">                    is_show=<span class="literal">True</span>, trigger=<span class="string">&quot;axis&quot;</span>, axis_pointer_type=<span class="string">&quot;shadow&quot;</span></span><br><span class="line">                ),</span><br><span class="line">            )</span><br><span class="line">        )</span><br><span class="line">        <span class="keyword">return</span> bar</span><br><span class="line">    timeline = Timeline(init_opts=opts.InitOpts(width=<span class="string">&quot;1000px&quot;</span>, height=<span class="string">&quot;500px&quot;</span>))</span><br><span class="line">    <span class="keyword">for</span> y <span class="keyword">in</span> range(<span class="number">2002</span>, <span class="number">2015</span>):</span><br><span class="line">        timeline.add(get_year_overlap_chart(year=y), time_point=str(y))</span><br><span class="line">    timeline.add_schema(is_auto_play=<span class="literal">True</span>, play_interval=<span class="number">1000</span>)</span><br><span class="line">    timeline.render(dir_to_save + <span class="string">&quot;TypicalPublishers_timeline_bar.html&quot;</span>)</span><br><span class="line">    print(<span class="string">&quot;Successfully drew TypicalPublishers_timeline_bar&quot;</span>)</span><br></pre></td></tr></table></figure>
<p>  雷达图</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">RadarChart</span>(<span class="params">BookNumsOfPubs: list, NamesOfPubs: list, AvgPoints: list, AvgPrice: list</span>):</span></span><br><span class="line">    <span class="keyword">global</span> dir_to_save</span><br><span class="line">    AvgPrice = [[x * <span class="number">80</span> <span class="keyword">for</span> x <span class="keyword">in</span> AvgPrice]]  <span class="comment"># 价格放大到原来的80倍</span></span><br><span class="line">    AvgPoints = [[math.exp(x) <span class="keyword">for</span> x <span class="keyword">in</span> tqdm(AvgPoints)]]  <span class="comment"># 平均分取指数，放大差异</span></span><br><span class="line">    BookNumsOfPubs = [[<span class="number">5</span> * x <span class="keyword">for</span> x <span class="keyword">in</span> BookNumsOfPubs]]  <span class="comment"># 书籍数量放大5倍,与放大后的评分在同一数量级，便于可视化</span></span><br><span class="line">    <span class="comment"># 以上数据处理方式没有什么理论依据，仅仅是调整到了一个数量级。有关的统计学知识后续学习</span></span><br><span class="line">    (</span><br><span class="line">        Radar(init_opts=opts.InitOpts(width=<span class="string">&quot;1000px&quot;</span>, height=<span class="string">&quot;500px&quot;</span>, bg_color=<span class="string">&quot;#CCCCCC&quot;</span>))</span><br><span class="line">            .add_schema(</span><br><span class="line">            schema=[</span><br><span class="line">                opts.RadarIndicatorItem(name=NamesOfPubs[<span class="number">0</span>], max_=<span class="number">5500</span>),</span><br><span class="line">                opts.RadarIndicatorItem(name=NamesOfPubs[<span class="number">1</span>], max_=<span class="number">5500</span>),</span><br><span class="line">                opts.RadarIndicatorItem(name=NamesOfPubs[<span class="number">2</span>], max_=<span class="number">5500</span>),</span><br><span class="line">                opts.RadarIndicatorItem(name=NamesOfPubs[<span class="number">3</span>], max_=<span class="number">5500</span>),</span><br><span class="line">                opts.RadarIndicatorItem(name=NamesOfPubs[<span class="number">4</span>], max_=<span class="number">5500</span>),</span><br><span class="line">                opts.RadarIndicatorItem(name=NamesOfPubs[<span class="number">5</span>], max_=<span class="number">5500</span>),</span><br><span class="line">                opts.RadarIndicatorItem(name=NamesOfPubs[<span class="number">6</span>], max_=<span class="number">5500</span>),</span><br><span class="line">                opts.RadarIndicatorItem(name=NamesOfPubs[<span class="number">7</span>], max_=<span class="number">5500</span>),</span><br><span class="line">                opts.RadarIndicatorItem(name=NamesOfPubs[<span class="number">8</span>], max_=<span class="number">5500</span>),</span><br><span class="line">                opts.RadarIndicatorItem(name=NamesOfPubs[<span class="number">9</span>], max_=<span class="number">5500</span>),</span><br><span class="line">            ],</span><br><span class="line">            splitarea_opt=opts.SplitAreaOpts(</span><br><span class="line">                is_show=<span class="literal">True</span>, areastyle_opts=opts.AreaStyleOpts(opacity=<span class="number">1</span>)</span><br><span class="line">            ),</span><br><span class="line">            textstyle_opts=opts.TextStyleOpts(color=<span class="string">&quot;#228B22&quot;</span>),</span><br><span class="line">        )</span><br><span class="line">            .add(</span><br><span class="line">            series_name=<span class="string">&quot;平均分(取指数后)&quot;</span>,</span><br><span class="line">            data=AvgPoints,</span><br><span class="line">            linestyle_opts=opts.LineStyleOpts(color=<span class="string">&quot;#D9173B&quot;</span>),</span><br><span class="line">        )</span><br><span class="line">            .add(</span><br><span class="line">            series_name=<span class="string">&quot;出版物数量(扩大5倍后)&quot;</span>,</span><br><span class="line">            data=BookNumsOfPubs,</span><br><span class="line">            linestyle_opts=opts.LineStyleOpts(color=<span class="string">&quot;#0000CD&quot;</span>),</span><br><span class="line">        )</span><br><span class="line">            .add(</span><br><span class="line">            series_name=<span class="string">&quot;出版物均价(扩大80倍后)&quot;</span>,</span><br><span class="line">            data=AvgPrice,</span><br><span class="line">            linestyle_opts=opts.LineStyleOpts(color=<span class="string">&quot;#FFD700&quot;</span>),</span><br><span class="line">        )</span><br><span class="line">            .set_series_opts(label_opts=opts.LabelOpts(is_show=<span class="literal">False</span>))</span><br><span class="line">            .set_global_opts(</span><br><span class="line">            title_opts=opts.TitleOpts(title=<span class="string">&quot;出版物数量前10的出版社&quot;</span>), legend_opts=opts.LegendOpts()</span><br><span class="line">        )</span><br><span class="line">            .render(dir_to_save + <span class="string">&quot;Top10PubsInBookNums_radar.html&quot;</span>)</span><br><span class="line">    )</span><br><span class="line">    print(<span class="string">&quot;Successfully drew Top10PubsInBookNums_radar&quot;</span>)</span><br></pre></td></tr></table></figure>
<p>  漏斗图</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">FunnelSort</span>(<span class="params">PriceOfAllBooks: list</span>):</span></span><br><span class="line">    <span class="keyword">global</span> dir_to_save</span><br><span class="line">    attr = [<span class="string">&#x27;0-20&#x27;</span>, <span class="string">&#x27;20-40&#x27;</span>, <span class="string">&#x27;40-60&#x27;</span>, <span class="string">&#x27;60-80&#x27;</span>, <span class="string">&#x27;80-100&#x27;</span>, <span class="string">&#x27;100-150&#x27;</span>, <span class="string">&#x27;150-∞&#x27;</span>]  <span class="comment"># 指定的价格区间</span></span><br><span class="line">    BooksOfSpecializedRange = [<span class="number">0</span> <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">7</span>)]  <span class="comment"># 用来存放指定价格区间的书籍数量的列表，与上面的attr对应，初始化为0</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> PriceOfAllBooks:</span><br><span class="line">        <span class="keyword">if</span> i &lt;= <span class="number">20</span>:</span><br><span class="line">            BooksOfSpecializedRange[<span class="number">0</span>] += <span class="number">1</span></span><br><span class="line">        <span class="keyword">elif</span> <span class="number">20</span> &lt; i &lt;= <span class="number">40</span>:</span><br><span class="line">            BooksOfSpecializedRange[<span class="number">1</span>] += <span class="number">1</span></span><br><span class="line">        <span class="keyword">elif</span> <span class="number">40</span> &lt; i &lt;= <span class="number">60</span>:</span><br><span class="line">            BooksOfSpecializedRange[<span class="number">2</span>] += <span class="number">1</span></span><br><span class="line">        <span class="keyword">elif</span> <span class="number">60</span> &lt; i &lt;= <span class="number">80</span>:</span><br><span class="line">            BooksOfSpecializedRange[<span class="number">3</span>] += <span class="number">1</span></span><br><span class="line">        <span class="keyword">elif</span> <span class="number">80</span> &lt; i &lt;= <span class="number">100</span>:</span><br><span class="line">            BooksOfSpecializedRange[<span class="number">4</span>] += <span class="number">1</span></span><br><span class="line">        <span class="keyword">elif</span> <span class="number">100</span> &lt; i &lt;= <span class="number">150</span>:</span><br><span class="line">            BooksOfSpecializedRange[<span class="number">5</span>] += <span class="number">1</span></span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            BooksOfSpecializedRange[<span class="number">6</span>] += <span class="number">1</span></span><br><span class="line">    c = (</span><br><span class="line">        Funnel()</span><br><span class="line">            .add(</span><br><span class="line">            <span class="string">&quot;书籍价格区间&quot;</span>,</span><br><span class="line">            [list(z) <span class="keyword">for</span> z <span class="keyword">in</span> tqdm(zip(attr, BooksOfSpecializedRange))],</span><br><span class="line">            sort_=<span class="string">&quot;ascending&quot;</span>,</span><br><span class="line">            label_opts=opts.LabelOpts(position=<span class="string">&quot;inside&quot;</span>),</span><br><span class="line">        )</span><br><span class="line">            .set_global_opts(title_opts=opts.TitleOpts(title=<span class="string">&quot;不同价格区间的书籍数量&quot;</span>,</span><br><span class="line">                                                       pos_top=<span class="string">&#x27;10%&#x27;</span>)</span><br><span class="line">                             )</span><br><span class="line">            .render(dir_to_save + <span class="string">&quot;PriceRange_funnel.html&quot;</span>)</span><br><span class="line">    )</span><br><span class="line">    print(<span class="string">&quot;Successfully drew PriceRange_funnel&quot;</span>)</span><br></pre></td></tr></table></figure>
</li>
<li><p>main函数</p>
<blockquote>
<p>将上述函数按顺序整合，并且添加提示性输出语句</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span>():</span></span><br><span class="line">    <span class="comment"># 数据载入、存储、清洗</span></span><br><span class="line">    print(<span class="string">&quot;Merging files......&quot;</span>)</span><br><span class="line">    ls = MergeFiles()  <span class="comment"># 合并文件，读文件，返回列表</span></span><br><span class="line">    new_ls = DataClean(ls)  <span class="comment"># 把格式不正确读不出来数据的行删掉,生成新列表</span></span><br><span class="line">    Data = GenerateListAndDf(new_ls)  <span class="comment"># 生成DataFrame格式的总数据</span></span><br><span class="line">    print(<span class="string">&quot;Data loading and storage cleaning is done successfully&quot;</span>)</span><br><span class="line">    Top20WritersNames, Top20WritersNums, Top20WritersPoints = RankOfCompositionNums(Data)</span><br><span class="line">    BookNumsOfPubs, NamesOfPubs, AvgPoints, AvgPrice, PriceOfAllBooks = RankOfPublisher(Data)</span><br><span class="line">    data_points, data_nums, data_all_published = DictOfDicts(Data)</span><br><span class="line">    print(<span class="string">&quot;All the datas are prepared successfully\nReady to draw&quot;</span>)</span><br><span class="line">    TimelineBar(Data)</span><br><span class="line">    TimelinePie(data_nums)</span><br><span class="line">    FunnelSort(PriceOfAllBooks)</span><br><span class="line">    BarAndLine(Top20WritersNames, Top20WritersNums, Top20WritersPoints)</span><br><span class="line">    RadarChart(BookNumsOfPubs, NamesOfPubs, AvgPoints, AvgPrice)</span><br><span class="line">    print(<span class="string">&quot;All the charts are completed successfully&quot;</span>)</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="主程序"><a href="#主程序" class="headerlink" title="主程序"></a>主程序</h3><blockquote>
<p>设置生成图标的目录，调用main函数</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">dir_to_save = <span class="string">&#x27;./Charts/&#x27;</span>  <span class="comment"># 图片保存路径，在每个绘图函数里声明为全局变量</span></span><br><span class="line">main()</span><br></pre></td></tr></table></figure>

<h2 id="可视化结果展示及分析"><a href="#可视化结果展示及分析" class="headerlink" title="可视化结果展示及分析"></a>可视化结果展示及分析</h2><ol>
<li>柱状图和折线图</li>
</ol>
<blockquote>
<p>高产作家中除郭敬明均分在6.9分外，其他均在7分以上，可见高产作家的书还是值得一读的。其中，国学大师钱钟书、蒋勋更是少而精的典范。遗憾的是，受限于技术类书籍本身的特点，其作者很难进入这个榜单。</p>
</blockquote>
<ol start="2">
<li><p>漏斗图<br><img src="./Charts_backup/PriceRange_funnel.png"></p>
<blockquote>
<p>书的价格大致符合正态分布，结合后续的雷达图可以发现，文学类书籍的价位通常要比技术类书籍的价位低一些</p>
</blockquote>
</li>
<li><p>雷达图<br><img src="./Charts_backup/Top10PubsInBookNums_radar.png"></p>
<blockquote>
<p>人民文学出版社、三联书店、译林出版社的评分较高，而主要出版技术类书籍的机械工业出版社与人民邮电出版社，虽然数量占优，但是评分却不是很高。“出版要为教育服务”，我国专业教材的建设任重而道远，而这也是世界一流大学建设的必经之路</p>
</blockquote>
</li>
<li><p>时间线饼图和时间线柱状图</p>
</li>
</ol>
<ul>
<li>注意！！！这里的出版物数量占比仅仅考虑了八家出版社，即八家出版社的数量为100%<br><img src="./Charts_backup/TypicalPublishers_timeline_bar.png"><br><img src="./Charts_backup/TypicalPublishers_timeline_pie.png"></li>
</ul>
<blockquote>
<p>02、03年，人民文学出版社出版量最大，04年开始，上海译文出版社出版量显著提升并之后一直占较大份额，10年往后，科技类出版社的出版量明显增加，而文学类出版社的出版量较少。<br>这明显反映了近年来信息产业的快速发展，但与此同时也不能忽视人文素养的陶冶<br>此外，因为仅仅取了8家出版社，结论或许有些片面</p>
</blockquote>
<h2 id="待改善之处"><a href="#待改善之处" class="headerlink" title="待改善之处"></a>待改善之处</h2><ol>
<li>选取数据的时候没有仔细看，数据集未包含评论人数、评分人数等反映书籍受欢迎程度的数据，导致有些信息无法呈现</li>
<li>数据集包含繁体字，处理时未统一转成简体中文，因此结果可能有些许误差<br>简繁体转换方法：<a target="_blank" rel="noopener" href="https://www.cnblogs.com/tangxin-blog/p/5616415.html">https://www.cnblogs.com/tangxin-blog/p/5616415.html</a></li>
<li>没有熟练掌握numpy、matplotlib和pandas，仅仅是面向应用学习，没有把库的方法大致过一遍，所以无法高效利用文档或者书籍，不知道有某个方法。因此数据处理时有些想法无法实现，或者只是用python本身的方法，很不优雅。后续打算把《利用python进行数据分析》中的内容都大致过一遍，有个印象，然后入门西瓜书，不过可能要等到暑假了</li>
<li>运用了pyecharts库，少数参数没有搞明白（要用的参数明白了，不然然出不了图），面向对象设计方法也没有学习。</li>
<li>因为3和4的缘故，代码太冗余，不够简洁</li>
<li>函数式编程与自顶向下设计方法的精髓没有掌握，仅仅是用函数将代码功能分了类，没有实现代码复用</li>
</ol>

      
    </div><!-- .entry-content -->

    <footer class="entry-meta">
    <a href="/CivilProgrammer/2020/05/11/PythonDataAnalysis-report/">
    <time datetime="2020-05-10T16:02:05.000Z" class="entry-date">
        2020-05-11
    </time>
</a>
    
    
    </footer>
</article>


    
<nav class="nav-single">
    <h3 class="assistive-text">文章导航</h3>
    
        <span class="nav-previous"><a href="/CivilProgrammer/2020/05/17/%E6%88%91%E7%9A%84%E6%88%90%E9%95%BF%E7%BB%8F%E5%8E%86/" rel="prev"><span class="meta-nav">←</span> 我的成长经历——心理健康教育课程大作业</a></span>
    
    
        <span class="nav-next"><a href="/CivilProgrammer/2020/05/10/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90%E5%A4%A7%E4%BD%9C%E4%B8%9A%E4%BB%A3%E7%A0%81%E5%86%99%E5%AE%8C%E5%95%A6/" rel="next">数据分析大作业代码写完啦 <span class="meta-nav">→</span></a></span>
    
</nav><!-- .nav-single -->







</div></div>
        <div id="secondary" class="widget-area" role="complementary">
  
    <aside id="search" class="widget widget_search"><form role="search" method="get" accept-charset="utf-8" id="searchform" class="searchform" action="//google.com/search">
    <div>
        <input type="text" value="" name="s" id="s" />
        <input type="submit" id="searchsubmit" value="搜索" />
    </div>
</form></aside>
  
    
  
    
  
    
  <aside class="widget">
    <h3 class="widget-title">Recents</h3>
    <div class="widget-content">
      <ul>
        
          <li>
            <a href="/CivilProgrammer/2021/02/18/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E6%9F%A5%E6%89%BE%E7%AB%A0%E8%8A%82%E4%B9%A0%E9%A2%98%E5%88%B7%E5%AE%8C/">数据结构查找章节习题刷完</a>
          </li>
        
          <li>
            <a href="/CivilProgrammer/2021/02/13/vmware%E4%B8%ADcentos7%E4%B8%8BNAT%E6%A8%A1%E5%BC%8F%E8%AE%BE%E7%BD%AE%E9%9D%99%E6%80%81ip/">vmware中centos7下NAT模式设置静态ip</a>
          </li>
        
          <li>
            <a href="/CivilProgrammer/2020/12/31/2020-12-31/">2020-12-31</a>
          </li>
        
          <li>
            <a href="/CivilProgrammer/2020/12/06/VSCode%E4%B8%AD%E6%96%87%E8%BE%93%E5%87%BA%E4%B9%B1%E7%A0%81/">VSCode中文输出乱码</a>
          </li>
        
          <li>
            <a href="/CivilProgrammer/2020/10/10/%E5%BB%BA%E5%B7%A5%E7%B2%BE%E7%A5%9E%E4%BC%A0%E6%89%BF%E8%80%85%E8%AF%84%E9%80%89%E2%80%94%E2%80%94%E5%8B%A4%E5%A5%8B%E5%A5%BD%E5%AD%A6/">(no title)</a>
          </li>
        
      </ul>
    </div>
  </aside>

  
    
  
    
  
</div>
      </div>
      <footer id="colophon" role="contentinfo">
    <p>&copy; 2021 CivilProgrammer
    All rights reserved.</p>
    <p>Powered by <a href="http://hexo.io/" target="_blank">Hexo</a></p>
</footer>
    <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"1","bdMiniList":false,"bdPic":"","bdStyle":"2","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='/js/share.js'];</script>

<script src="/js/jquery-3.3.1.min.js"></script>


  
<link rel="stylesheet" href="/CivilProgrammer/fancybox/jquery.fancybox.css">

  
<script src="/CivilProgrammer/fancybox/jquery.fancybox.pack.js"></script>




<script src="/CivilProgrammer/js/script.js"></script>


<script src="/js/navigation.js"></script>

<div id="bg"></div>

  </div>
</body>
</html>